import launch
import launch.event_handlers
import launch_ros
import os
from ament_index_python.packages import get_package_share_directory
from launch.launch_description_sources import PythonLaunchDescriptionSource

def generate_launch_description():
    launch_description = launch.LaunchDescription()
    
    pkg_node = get_package_share_directory('node_pkg')
    
    topic_pub_sub_launch = launch.actions.IncludeLaunchDescription(
        PythonLaunchDescriptionSource(
            os.path.join(pkg_node, 'launch', 'topic_pub_sub.launch.py')
        ),
    )
    
    helloword_node=launch_ros.actions.Node(
        package="node_pkg",
        # 节点文件名称
        executable="helloword", 
        # 节点名称
        name="hellword_node",
    )
    
    launch_description.add_action(topic_pub_sub_launch)
    
    launch_description.add_action(launch.actions.RegisterEventHandler(
        event_handler= launch.event_handlers.OnProcessStart(
            # target_action= topic_pub_sub_launch,
            on_start=[
                launch.actions.LogInfo(msg="start topic_pub_sub_launch------------"),
                helloword_node
            ]
        )
    ))
   
    return launch_description